import Vue from "vue";
import Vuex from 'vuex'

Vue.use(Vuex);

// 设置默认城市
// let defaultCity = '广州';
// if (!localStorage.city) {
//     let defaultCity = '广州';
// } else {
//     let defaultCity = localStorage.city;
// }

export default new Vuex.Store({
    state: {
        arr: [],
        city: '广州',
        cityId: 20,
        cinemaId: null,
        // cinemaId: null,
        // city: defaultCity,
        searchData: [],
        resultData: [],
        cinemaData: []
    },

    mutations: {
        addArr(state, n) {

            state.arr.push(n);
        },

        changeCity(state, n) {
            state.city = n;
        },

        changeCityId(state, n) {
            state.cityId = n;
        },
        getCinemaId(state, id) {
            state.cinemaId = id;
        },

        // changeCity(state, cName) {
        //     state.city = cName;
        //     localStorage.city = cName;
        // },
        addHistory(state, search) {
            state.searchData.push(search);

        },

        // 删除历史记录
        removeHistory(state, index) {
            state.searchData.splice(index, 1);
        },

        addSearchResult(state, search) {
            state.resultData.push(search);

        },
        addCinemaResult(state, search) {
            state.cinemaData.push(search);

        },


    },

    actions: {
        removeHistory({ commit }, index) {
            commit('removeHistory', index);
        },
    }
})